#include "StdAfx.h"
#include ".\gameguild.h"
#include ".\GameGuildMember.h"
#include <Struct.h>

__IMPL_GUILDPOOL(GameGuild)
GameGuild::GameGuild(void)
{
	m_MemberHash.Initialize(_MAX_GUILDMEMBER_NUM);
}

GameGuild::~GameGuild(void)
{
	Destroy();
}

BOOL GameGuild::HaveRights( Player * pPlayer, eGUILD_RIGHTS right )
{

	return TRUE;
}

VOID GameGuild::Destroy()
{
	for( GUILDMEMBER_HASH_ITR it = m_MemberHash.begin() ; it != m_MemberHash.end() ; ++it )
	{
		(*it)->Release();
		GameGuildMember::FREE((*it));
	}
	m_MemberHash.RemoveAll();
}
VOID GameGuild::SelectInfo( PACKET_FOR_GUILD & OUT rGuildInfo )
{
	memcpy( rGuildInfo.m_tszGuildName, m_Info.m_tszGuildName, MAX_GUILDNAME_LENGTH*sizeof(TCHAR) );
	rGuildInfo.m_GuildGrade			= m_Info.m_GuildGrade;
	//m_MarkBinary[MAX_GUILDMARKSTREAM_SIZE];
	rGuildInfo.m_MasterCharGuid		= m_Info.m_MasterCharGuid;
	memcpy( rGuildInfo.m_tszMasterCharName, m_Info.m_tszMasterCharName, MAX_CHARNAME_LENGTH*sizeof(TCHAR) );
	rGuildInfo.m_GuildPoint			= m_Info.m_GuildPoint;
	rGuildInfo.m_UserPoint			= m_Info.m_UserPoint;
	rGuildInfo.m_RestrictedRight	= m_Info.m_RestrictedRight;
	rGuildInfo.m_GuildMoney			= m_Info.m_GuildMoney;
	rGuildInfo.m_GuildMemberNum		= GetMemberNum();
}
VOID GameGuild::Create( const BASE_GUILD_INFO & IN rInfo, const GUILD_MEMBER_INFO * pMemberInfo, BYTE MemberCount )
{
	memcpy( &m_Info, &rInfo, sizeof(BASE_GUILD_INFO) );
	
	for( int i = 0 ; i < MemberCount ; ++i )
	{
		ASSERT( !FindMember( pMemberInfo[i].m_CharGuid ) );
		GameGuildMember * pMember = GameGuildMember::ALLOC();
		pMember->Init(*pMemberInfo);
		AddMember( pMember, pMember->GetCharGuid() );
	}
}

VOID GameGuild::Withdraw( CHARGUID CharGuid )
{
	GameGuildMember * pMember = FindMember(CharGuid);
	ASSERT(pMember);
	RemoveMember( CharGuid );
	GameGuildMember::FREE(pMember);
}

VOID GameGuild::Join( const GUILD_MEMBER_INFO & IN rMemberInfo )
{
	GameGuildMember * pMember = GameGuildMember::ALLOC();
	pMember->Init(rMemberInfo);
	AddMember( pMember, pMember->GetCharGuid() );
}


